home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / d_widgets.pro < prev    next >
Text File  |  1997-07-08  |  51KB  |  1,460 lines

  1. ;$Id: d_widgets.pro,v 1.15 1997/04/24 18:09:46 tremblay Exp $
  2. ;
  3. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ;  FILE:
  8. ;       widgets.pro
  9. ;
  10. ;  CALLING SEQUENCE: widgets
  11. ;
  12. ;  PURPOSE:
  13. ;       shows every widgets available in IDL 5.0
  14. ;
  15. ;  MAJOR TOPICS: widgets
  16. ;
  17. ;  CATEGORY:
  18. ;       IDL 5.0
  19. ;
  20. ;  INTERNAL FUNCTIONS and PROCEDURES:
  21. ;       pro widgets_Event            -  Event handler
  22. ;       pro widgets_Cleanup          -  Cleanup
  23. ;       pro widgets                  -  Main procedure
  24. ;
  25. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  26. ;       fun cwtable                 -  Compound widget 
  27. ;       widgets.txt
  28. ;       base.gif
  29. ;       button.gif
  30. ;       draw.gif
  31. ;       droplist.gif
  32. ;       label.gif
  33. ;       list.gif
  34. ;       slider.gif
  35. ;       table.gif
  36. ;       text.gif
  37. ;
  38. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  39. ;
  40. ;  NAMED STRUCTURES:
  41. ;       none.
  42. ;
  43. ;  COMMON BLOCS:
  44. ;       none.
  45. ;
  46. ;  MODIFICATION HISTORY:
  47. ;       96,   DAT     - Written
  48. ;
  49. ;-
  50.  
  51. ; -----------------------------------------------------------------------------
  52. ;
  53. ;  Purpose:  Function returns the 3 angles of a space three 1-2-3
  54. ;            given a 3 x 3 cosine direction matrix
  55. ;            else -1 on failure.
  56. ;
  57. ;  Definition :  Given 2 sets of dextral orthogonal unit vectors
  58. ;                (a1, a2, a3) and (b1, b2, b3), the cosine direction matrix 
  59. ;                C (3 x 3) is defined as the dot product of:
  60. ;
  61. ;                C(i,j) = ai . bi  where i = 1,2,3 
  62. ;
  63. ;                A column vector X (3 x 1) becomes X' (3 x 1)
  64. ;                after the rotation as defined as :
  65. ;                
  66. ;                X' = C X
  67. ;
  68. ;                The space three 1-2-3 means that the x rotation is first,
  69. ;                followed by the y rotation, then the z.
  70. ;
  71. function angle3123, $
  72.     cosMat           ; IN: cosine direction matrix (3 x 3)
  73.  
  74.     ;  Verify the input parameters
  75.     ;
  76.     if (N_PARAMS() ne 1) then begin
  77.         PRINT,'Error in angle3123: 1 parameters must be passed.'
  78.         RETURN, -1
  79.     endif
  80.     sizec = size(cosMat)
  81.     if (sizec(0) ne 2) then begin
  82.         PRINT,'Error, the input matrix must be of dimension 2'
  83.         RETURN, -1
  84.     endif
  85.     if ((sizec(1) ne 3) or (sizec(2) ne 3)) then begin
  86.         PRINT,'Error, the input matrix must be 3 by 3'
  87.         RETURN, -1
  88.     endif
  89.     
  90.     ;  Compute the 3 angles (in degrees)
  91.     ;
  92.     cosMat = TRANSPOSE(cosMat)
  93.     angle = FLTARR(3)
  94.     angle(1) = -cosMat(2,0) 
  95.     angle(1) = ASIN(angle(1))
  96.     c2 = COS(angle(1))
  97.     if (ABS(angle(1)) lt 1.0e-6) then begin
  98.         angle(0) = ATAN(-cosMat(1,2), cosMat(1,1))
  99.         angle(2) = 0.0
  100.     endif else begin
  101.         angle(0) = ATAN( cosMat(2,1), cosMat(2,2))
  102.         angle(2) = ATAN( cosMat(1,0), cosMat(0,0))
  103.     endelse
  104.     angle = angle * (180.0/!DPI)
  105.  
  106.     RETURN, angle
  107.  
  108. end    ;   of angle3123
  109.  
  110.  
  111. ;$Id: d_widgets.pro,v 1.15 1997/04/24 18:09:46 tremblay Exp $
  112. ;
  113. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  114. ;       Unauthorized reproduction prohibited.
  115. ;
  116. ;+
  117. ;  FILE:
  118. ;       cwtable.pro
  119. ;
  120. ;  PURPOSE:
  121. ;       This compound widget shows the IDL 5.0 available
  122. ;       widgets.
  123. ;
  124. ;  CATEGORY:
  125. ;       IDL 5.0
  126. ;
  127. ;  CONTENTS:
  128. ;       function space3123           - compute the cosine direction matrix
  129. ;                                      of a space-three-123
  130. ;       pro GetDrawID                - get the window ID on realization
  131. ;       pro Mytable_Event            - event handler
  132. ;       pro cwtable                  - main procedure
  133. ;
  134. ;  FUNCTION/PROCEDURE CALLED
  135. ;       function angle3123           - compute the the angles
  136. ;                                      of a space-three-123
  137. ;
  138. ;  NAMED STRUCTURES:
  139. ;       none.
  140. ;
  141. ;  COMMON BLOCS:
  142. ;       none.
  143. ;
  144. ;  MODIFICATION HISTORY:
  145. ;       10/96,   DAT   - Written.
  146. ;-
  147. ; -----------------------------------------------------------------------------
  148. ;
  149. ;  Purpose:  Function returns the cosine direction matrix (3 x 3)
  150. ;            given the space three 1-2-3 rotation angles(i.e. rotation around
  151. ;            x axis, followed by Y axis, then z axis),
  152. ;            else -1 on failure.
  153. ;
  154. ;  Definition :  Given 2 sets of dextral orthogonal unit vectors
  155. ;                (a1, a2, a3) and (b1, b2, b3), the cosine direction matrix 
  156. ;                C (3 x 3) is defined as the dot product of:
  157. ;
  158. ;                C(i,j) = ai . bi  where i = 1,2,3 
  159. ;
  160. ;                A column vector X (3 x 1) becomes X' (3 x 1)
  161. ;                after the rotation as defined as :
  162. ;                
  163. ;                X' = C X
  164. ;
  165. function space3123, $
  166.     theta, $        ; IN: angle of rotation around the x axis(in degrees)
  167.     phi, $          ; IN: angle of rotation around the y axis(in degrees)
  168.     gamma           ; IN: angle of rotation around the z axis(in degrees)
  169.  
  170.     ;  Verify the input parameters.
  171.     ;
  172.     if (N_PARAMS() ne 3) then begin
  173.         PRINT,'Error in space3123: 3 parameters must be passed.'
  174.         RETURN, -1
  175.     endif
  176.  
  177.     cosMat = FLTARR(3, 3)
  178.     
  179.     ;  Transform the angle in radians.
  180.     ;
  181.     rTheta = theta * !DPI / 180.0
  182.     rPhi = Phi * !DPI / 180.0
  183.     rGamma = Gamma * !DPI / 180.0
  184.  
  185.     cos1 = COS(rTheta)
  186.     cos2 = COS(rPhi)
  187.     cos3 = COS(rGamma)
  188.     sin1 = SIN(rTheta)
  189.     sin2 = SIN(rPhi)
  190.     sin3 = SIN(rGamma)
  191.  
  192.     ;  Compute the cosine direction matrix.
  193.     ;
  194.     cosMat(0,0) = cos2*cos3 
  195.     cosMat(1,0) = cos2*sin3
  196.     cosMat(2,0) = -sin2
  197.     cosMat(0,1) = (sin1*sin2*cos3) - (cos1*sin3)
  198.     cosMat(1,1) = (sin1*sin2*sin3) + (cos1*cos3)
  199.     cosMat(2,1) = sin1*cos2
  200.     cosMat(0,2) = (cos1*sin2*cos3) + (sin1*sin3)
  201.     cosMat(1,2) = (cos1*sin2*sin3) - (sin1*cos3)
  202.     cosMat(2,2) = cos1*cos2 
  203.  
  204.     RETURN, cosMat
  205.  
  206. end    ;   of space3123
  207.  
  208. ; -----------------------------------------------------------------------------
  209. ;
  210. ;  Purpose:  On realization of the draw widget, get the window object ID,
  211. ;            and place it into the user value of the draw base  which
  212. ;            is the widget draw parent.
  213. ;
  214. pro GetDrawID, id
  215.  
  216.    WIDGET_CONTROL, id, GET_VALUE = drawWindowObjID
  217.    wDrawBase = WIDGET_INFO(id, /PARENT)
  218.    WIDGET_CONTROL, wDrawBase, SET_UVALUE =drawWindowObjID , /NO_COPY
  219.  
  220. end
  221.  
  222. ; -----------------------------------------------------------------------------
  223. ;
  224. ;  Purpose:  Handle the events of this compound widget.
  225. ;
  226. pro MyTable_Event, $
  227.     sEvent      ; IN: event structure
  228.  
  229.     ;  Quit the application using the close box.
  230.     ;
  231.     if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
  232.         'WIDGET_KILL_REQUEST') then begin
  233.         WIDGET_CONTROL, sEvent.top, /DESTROY
  234.         RETURN
  235.     endif
  236.  
  237.     ;  Get the info structure.
  238.     ;
  239.     child = WIDGET_INFO(sEvent.handler, /CHILD)
  240.     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  241.  
  242.     ;  Get the drawWindow  object identifier
  243.     ;  which is the user value of the draw base.
  244.     ;
  245.     WIDGET_CONTROL, sInfo.wDrawBase, $
  246.        GET_UVALUE=temp, /NO_COPY
  247.     oDrawWindowID = temp
  248.     WIDGET_CONTROL, sInfo.wDrawBase, $
  249.        SET_UVALUE=temp, /NO_COPY
  250.  
  251.     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  252.  
  253.     ;  Branch the event accordingly to its name and its user value.
  254.     ;
  255.     eventName = WIDGET_INFO(sEvent.id,/NAME) 
  256.     case eventName of
  257.  
  258.         'TABLE' : begin
  259.  
  260.             ;  Insertion of character.
  261.             ; 
  262.             if (sEvent.type eq 0) then begin 
  263.  
  264.                 ;  Take action only when the carriage return character
  265.                 ;  is typed.
  266.                 ;
  267.                 if (sEvent.ch EQ 13) then begin 
  268.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  269.                     WIDGET_CONTROL, sInfo.wDataTable, GET_VALUE=data, $
  270.                         USE_TABLE_SELECT=[0, 0, $
  271.                         sInfo.xdimension-1, sInfo.ydimension-1]
  272.                     highData = WHERE(data gt 9, countHigh)
  273.                     if(countHigh ne 0) then begin
  274.                         data(highData) = 9
  275.                     endif
  276.                     lowData = WHERE(data lt 0, countLow)
  277.                     if(countLow ne 0) then begin
  278.                         data(LowData) = 0
  279.                     endif
  280.                     if ((countHigh gt 0) or (countLow gt 0)) then begin
  281.                         WIDGET_CONTROL, sInfo.wDataTable, SET_VALUE=data, $
  282.                             USE_TABLE_SELECT=[0, 0, $
  283.                             sInfo.xdimension-1, sInfo.ydimension-1]
  284.                     endif
  285.  
  286.                     ;  Reset the vertex colors.
  287.                     ;
  288.                     xtot = sInfo.xdimension * sInfo.ydimension
  289.                     shades2 = FLTARR(xtot)
  290.                     shades2(0:xtot-1) = data(0:sInfo.xdimension-1, $
  291.                         0:sInfo.ydimension-1)
  292.                     maxshades = sInfo.maxDataValue
  293.                     minshades = sInfo.minDataValue
  294.                     sat = 1.0
  295.                     val = 1.0
  296.                     maxangle = 225.0  ; ( angle is  0 < .. < 360 )
  297.                     for j = 0, xtot-1 do begin
  298.                         angle =ROUND(  (shades2(j) - minshades) / $
  299.                         (maxshades-minshades) * maxangle )
  300.                         color_convert, angle, sat, $
  301.                             val, red, green, blue, /hsv_rgb
  302.                         sInfo.vertexColors(0, j) = red
  303.                         sInfo.vertexColors(1, j) = green
  304.                         sInfo.vertexColors(2, j) = blue
  305.                     endfor
  306.  
  307.                     ;  Draw the surface.
  308.                     ;
  309.                     if(sInfo.vertexFlag eq 1) then begin
  310.                         sInfo.oSimpleSurface->SetProperty, $
  311.                             VERT_COLORS=sInfo.vertexColors
  312.                     endif
  313.                     sInfo.oSimpleSurface->SetProperty, DATAZ=data
  314.                     oDrawWindowID->Draw, sInfo.oView
  315.  
  316.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  317.                 endif
  318.             endif
  319.  
  320.         end        ;   of TABLE
  321.  
  322.         'BUTTON' : begin
  323.  
  324.             WIDGET_CONTROL, sEvent.id, GET_UVALUE=uvalue
  325.  
  326.             case uvalue of
  327.  
  328.                 'POPINFO' : begin
  329.                     void = DIALOG_MESSAGE('This message window is modal.' + $
  330.                            'Press OK to continue')
  331.                 end           ;  of POPINFO
  332.  
  333.                 'INFO' : begin
  334.                     if( Xregistered('XDisplayFile') ne 0) then RETURN
  335.                     XDisplayFile, filepath("widgets.txt", $
  336.                         SUBDIR=['examples','demo','demotext']), $
  337.                         DONE_BUTTON='Done', $
  338.                         TITLE="About widgets", $
  339.                         GROUP=sEvent.top, WIDTH=55, HEIGHT=14
  340.                 end           ;  of INFO
  341.  
  342.                 'QUIT' : begin
  343.  
  344.                     ;  Destroy the parent of cwtable, i.e
  345.                     ;  destroy everything.
  346.                     ;
  347.                     child = WIDGET_INFO(sEvent.handler, /CHILD)
  348.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  349.                     WIDGET_CONTROL, sInfo.parent, /DESTROY
  350.                 end           ;  of QUIT
  351.  
  352.             endcase       ;  of uvalue
  353.  
  354.         end               ;   of BUTTON
  355.  
  356.         'DROPLIST' : begin
  357.  
  358.             listValue = WIDGET_INFO( sEvent.id, /DROPLIST_SELECT)
  359.             WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  360.  
  361.             case listValue of
  362.    
  363.                 ;  Wire style.
  364.                 ;
  365.                 0 : begin
  366.                     sInfo.oSimpleSurface->SetProperty, STYLE=1
  367.                     oDrawWindowID->Draw, sInfo.oView
  368.                 end    ;    of 0
  369.  
  370.                 ;  Solid style.
  371.                 ;
  372.                 1 : begin
  373.                     sInfo.oSimpleSurface->SetProperty, STYLE=2
  374.                     oDrawWindowID->Draw, sInfo.oView
  375.                 end    ;    of 1
  376.  
  377.                 ;  Lego solid style.
  378.                 ;
  379.                 2 : begin
  380.                     sInfo.oSimpleSurface->SetProperty, STYLE=6
  381.                     oDrawWindowID->Draw, sInfo.oView
  382.                 end    ;    of 2
  383.  
  384.             endcase     ;  of listValue
  385.  
  386.             WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  387.  
  388.         end       ;   of DROPLIST
  389.  
  390.         ;  Handle the CW_FIELD text event (a BASE event is returned here).
  391.         ;
  392.         'BASE' : begin
  393.  
  394.             WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  395.             WIDGET_CONTROL, sInfo.wStatusLabel, SET_VALUE=sEvent.value
  396.             WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  397.  
  398.         end     ;  of  BASE
  399.  
  400.         ;  Handle the list event, Choose between 4 color scenarios.
  401.         ;
  402.         'LIST' : begin
  403.  
  404.             WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  405.             listValue = WIDGET_INFO( sEvent.id, /LIST_SELECT)
  406.  
  407.             case listValue of
  408.  
  409.                 ;  White.
  410.                 ;
  411.                 0 : begin
  412.                     sInfo.oSimpleSurface->SetProperty, VERT_COLORS=0
  413.                     sInfo.oSimpleSurface->SetProperty, COLOR=[255,255,255]
  414.                     oDrawWindowID->Draw, sInfo.oView
  415.                     sInfo.vertexFlag=0
  416.                 end    ;  of 0
  417.  
  418.                 ;  Yellow.
  419.                 ;
  420.                 1 : begin
  421.                     sInfo.oSimpleSurface->SetProperty, VERT_COLORS=0
  422.                     sInfo.oSimpleSurface->SetProperty, COLOR=[255,255,0]
  423.                     oDrawWindowID->Draw, sInfo.oView
  424.                     sInfo.vertexFlag=0
  425.                 end    ;  of 1
  426.  
  427.                 ;  Red.
  428.                 ;
  429.                 2 : begin
  430.                     sInfo.oSimpleSurface->SetProperty, VERT_COLORS=0
  431.                     sInfo.oSimpleSurface->SetProperty, COLOR=[255,0,0]
  432.                     oDrawWindowID->Draw, sInfo.oView
  433.                     sInfo.vertexFlag=0
  434.                 end    ;  of 2
  435.  
  436.                 ;  Rainbow or Hue.
  437.                 ;
  438.                 3 : begin
  439.                     sInfo.oSimpleSurface->SetProperty, $
  440.                         VERT_COLORS=sInfo.vertexColors
  441.                     oDrawWindowID->Draw, sInfo.oView
  442.                     sInfo.vertexFlag=1
  443.                 end    ;  of 3
  444.  
  445.             endcase
  446.  
  447.             WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  448.  
  449.         end     ;   of LIST
  450.  
  451.         ;  Handle the rotation.
  452.         ;
  453.         'SLIDER' : begin
  454.  
  455.             WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  456.             WIDGET_CONTROL, sInfo.wXSlider, GET_VALUE=xDegree
  457.             WIDGET_CONTROL, sInfo.wYSlider, GET_VALUE=yDegree
  458.             WIDGET_CONTROL, sInfo.wZSlider, GET_VALUE=zDegree
  459.             matFinal = FLTARR(3,3)
  460.             matFinal = space3123(xDegree, yDegree, zDegree)
  461.  
  462.             sInfo.oRotationModel->GetProperty, TRANSFORM=t
  463.             tempMat = FLTARR(3,3)
  464.             tempMat(0:2, 0:2) = TRANSPOSE(t(0:2, 0:2))
  465.             tempMat = TRANSPOSE(tempMat)
  466.             rotMat = matFinal # tempMat
  467.  
  468.             ;  Find the Euler parameters 'e4' of rotMat
  469.             ;  which is the rotation it takes to go from
  470.             ;  the original (t) to the final (matFinal).
  471.             ;
  472.             e4 = 0.5 * SQRT(1.0 + rotMat(0,0) + $
  473.                 rotMat(1,1) + rotMat(2,2))
  474.            
  475.             ;  Find the unit vector of the single rotation axis
  476.             ;  and the angle of rotation.
  477.             ;
  478.             if (e4 eq 0) then begin
  479.                 if (rotMat(0,0) eq 1) then begin
  480.                     axisRot = [1, 0, 0]
  481.                 endif else if(rotMat(1,1) eq 1) then begin
  482.                     axisRot = [0, 1, 0]
  483.                 endif else begin
  484.                     axisRot = [0, 0, 1]
  485.                 endelse
  486.                 angleRot = 180.0
  487.             endif else begin
  488.                 e1 = (rotMat(2,1) - rotMat(1,2))/(4.0*e4)
  489.                 e2 = (rotMat(0,2) - rotMat(2,0))/(4.0*e4)
  490.                 e3 = (rotMat(1,0) - rotMat(0,1))/(4.0*e4)
  491.                 modulusE = SQRT(e1*e1 + e2*e2 +e3*e3)
  492.                 if(modulusE eq 0.0) then begin
  493.                     WIDGET_CONTROL, child, $
  494.                         SET_UVALUE=sInfo, /NO_COPY
  495.                     RETURN
  496.                 endif
  497.                 axisRot = FLTARR(3)
  498.                 axisRot(0) = e1/modulusE
  499.                 axisRot(1) = e2/modulusE
  500.                 axisRot(2) = e3/modulusE
  501.                 angleRot = (2.0 * ACOS(e4)) * 180 / !DPI
  502.             endelse
  503.  
  504.             for i = 0, 2 do begin
  505.                 if(ABS(axisRot(i)) lt 1.0e-6) then axisRot(i)=1.0e-6
  506.             endfor
  507.             sInfo.oRotationModel->Rotate, axisRot, angleRot
  508.             oDrawWindowID->Draw, sInfo.oView
  509.  
  510.             WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  511.  
  512.         end    ;  of SLIDER
  513.  
  514.         'DRAW': begin
  515.             WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  516.  
  517.             ;  Expose.
  518.             ;
  519.             if (sEvent.type eq 4) then begin
  520.                 oDrawWindowID->Draw, sInfo.oView
  521.                 WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  522.                 RETURN
  523.             endif
  524.  
  525.  
  526.             ;  Handle trackball update
  527.             ;
  528.             bHaveTransform = sInfo.oTrack->Update(sEvent, TRANSFORM=qmat )
  529.             if (bHaveTransform NE 0) then begin
  530.                 sInfo.oRotationModel->GetProperty, TRANSFORM=t
  531.                 mt = t # qmat
  532.                 sInfo.oRotationModel->SetProperty,TRANSFORM=mt
  533.             endif
  534.  
  535.             ;  Button press.
  536.             ;
  537.             if (sEvent.type eq 0) then begin
  538.                 sInfo.btndown = 1B
  539.                 oDrawWindowID->SetProperty, QUALITY=2
  540.                 WIDGET_CONTROL, sInfo.wAreaDraw, /DRAW_MOTION
  541.             endif    ;     of Button press
  542.  
  543.             ;  Button motion.
  544.             ;
  545.             if ((sEvent.type eq 2) and (sInfo.btndown eq 1B)) then begin
  546.  
  547.                 if (bHaveTransform) then begin
  548.                     ;  Reset the x, y, z axis angle values.
  549.                     ;
  550.                     sInfo.oRotationModel->GetProperty, TRANSFORM=transform
  551.                     tempMat = FLTARR(3,3)
  552.                     xyzAngles = FLTARR(3)
  553.                     tempMat(0:2, 0:2) = transform(0:2, 0:2)
  554.                     xyzAngles = Angle3123(tempMat)
  555.                     WIDGET_CONTROL, sInfo.wXSlider, SET_VALUE=xyzAngles(0)
  556.                     WIDGET_CONTROL, sInfo.wYSlider, SET_VALUE=xyzAngles(1)
  557.                     WIDGET_CONTROL, sInfo.wZSlider, SET_VALUE=xyzAngles(2)
  558.                     oDrawWindowID->Draw, sInfo.oView
  559.                 endif
  560.  
  561.             endif     ;   of Button motion
  562.  
  563.             ;  Button release.
  564.             ;
  565.             if (sEvent.type eq 1) then begin
  566.                 if (sInfo.btndown EQ 1b) then begin
  567.                     oDrawWindowID->SetProperty, QUALITY=2
  568.                     oDrawWindowID->Draw, sInfo.oView
  569.                 endif
  570.                 sInfo.btndown = 0B
  571.                 WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_MOTION=0
  572.             endif
  573.             WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  574.         end                 ;     of DRAW
  575.  
  576.         else : begin
  577.             print, 'This event is not handled.'
  578.         end    ;  of else
  579.  
  580.     endcase
  581.         
  582. end    ;  of event handler
  583.  
  584. ;----------------------------------------------------------------------------
  585. ;
  586. ;  Purpose:  This application shows the thuse of every widgets
  587. ;            available in IDL 5.0. Namely : base, button, slider,
  588. ;            droplist, list, label, draw, table, text, and messasge.
  589. ;
  590. ;  This application is a compound widget and must be called by
  591. ;  a driver (main) application. It returns the top level base
  592. ;  (sCWBase) of the compound widget.
  593. ;
  594. ;  Additional information: in the driver code (main), in order to get
  595. ;  the info structure and the draw window object ID, type this:
  596. ;  
  597. ;  child = WIDGET_INFO(wCWBase, /CHILD)
  598. ;  WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  599. ;  WIDGET_CONTROL,sInfo.wDrawBase, GET_UVALUE=oDrawWindowID, /NO_COPY
  600. ;
  601. function cwtable, $
  602.     parent, $            ; IN:  parent base
  603.     XOFFSET=xOffset, $   ; IN:  (opt) x offset (in pixel)
  604.     YOFFSET=yOffset, $   ; IN:  (opt) x offset (in pixel)
  605.     MAPFLAG=mapFlag      ; IN: (opt)  0=  not showing, 1= showing
  606.     
  607.     if (N_PARAMS() ne 1) then begin
  608.         PRINT,'Error: 1 parameter must be passed'
  609.         RETURN, -1L
  610.     endif
  611.  
  612.     ;  Set the dimension of the draw widget.
  613.     ;
  614.     Device, GET_SCREEN_SIZE = screenDim
  615.     xdim = screenDim(0)*0.3
  616.     ydim = screenDim(1)*0.3
  617.  
  618.     ;  Create a surface.
  619.     ;
  620.     data = dist(10)
  621.     xArray = INDGEN(10)
  622.     yArray = INDGEN(10)
  623.  
  624.     ;  Set up the default parameters.
  625.     ;
  626.     if (N_ELEMENTS(mapFlag) eq 0) then begin
  627.         mapFlag = 1
  628.     endif
  629.  
  630.     if ((mapFlag NE 0) and (mapFlag NE 1)) then begin
  631.         mapFlag = 1
  632.     endif
  633.  
  634.     if (N_ELEMENTS(xOffset) EQ 0) then begin
  635.         xOffset = 0
  636.     endif
  637.  
  638.     if (N_ELEMENTS(yOffset) EQ 0) then begin
  639.         yOffset = 0
  640.     endif
  641.  
  642.     ;  Get the tips.
  643.     ;
  644.     sText = getTips(filepath('widgets.tip', $
  645.         SUBDIR=['examples','demo', 'demotext']) )
  646.  
  647.  
  648.     ;  Create the top level base.
  649.     ;
  650.     wCWBase = WIDGET_BASE( /COLUMN, YPAD=0, XPAD=0, $
  651.         MBAR=barBase, TLB_FRAME_ATTR=1, TITLE='Widgets', $
  652.         MAP=mapFlag, SPACE=15, GROUP_LEADER=parent,  $
  653.         /TLB_KILL_REQUEST_EVENTS, $
  654.         XOFFSET=xOffset, YOFFSET=yOffset)
  655.  
  656.         ;  Create the file menu bar item that contains the quit button.
  657.         ;
  658.         wFileButton = WIDGET_BUTTON(barBase, VALUE='File', /MENU)
  659.  
  660.             wQuitButton = WIDGET_BUTTON(wFileButton, $
  661.                 VALUE='Quit', UVALUE='QUIT')
  662.  
  663.         ;  Create the menu bar item help that contains the about button.
  664.         ;
  665.         wHelpButton = WIDGET_BUTTON(barBase, VALUE='About', /HELP, /MENU)
  666.  
  667.             wAboutButton = WIDGET_BUTTON(wHelpButton, $
  668.                 VALUE='About Widgets', UVALUE='INFO')
  669.  
  670.         ;  Create the first child of the graghic base.
  671.         ;
  672.         wSubBase = WIDGET_BASE(wCWBase, COLUMN=2)
  673.  
  674.             ;  Create a base for the left column.
  675.             ;
  676.             wLeftBase = WIDGET_BASE(wSubBase, /BASE_ALIGN_CENTER, $
  677.                /COLUMN)
  678.  
  679.                 wStyleBase = WIDGET_BASE(wLeftBase, /COLUMN, $
  680.                     /FRAME, MAP=mapFlag)
  681.  
  682.                     wStyleDroplist = WIDGET_DROPLIST(wStyleBase, $
  683.                         VALUE=['Wire', 'Solid', 'Lego Solid'], $
  684.                         UVALUE='STYLELIST', TITLE='Style')
  685.               
  686.                 wSliderBase = WIDGET_BASE(wLeftBase, /COLUMN, $
  687.                     /FRAME, YPAD=8, XPAD=8, MAP=mapFlag)
  688.  
  689.                     wSliderLabel = WIDGET_LABEL(wSliderBase, $
  690.                         VALUE='Rotation', /ALIGN_CENTER)
  691.  
  692.                     wXSlider = WIDGET_SLIDER(wSliderBase, $
  693.                         VALUE=-45, MINIMUM=-180, MAXIMUM=180, $
  694.                         UVALUE='XROTATION')
  695.  
  696.                     wSliderXLabel = WIDGET_LABEL(wSliderBase, $
  697.                         VALUE='X Axis')
  698.  
  699.                     wYSlider = WIDGET_SLIDER(wSliderBase, $
  700.                         VALUE=45, MINIMUM=-180, MAXIMUM=180, $
  701.                         UVALUE='YROTATION')
  702.  
  703.                     wSliderYLabel = WIDGET_LABEL(wSliderBase, $
  704.                         VALUE='Y Axis')
  705.  
  706.                     wZSlider = WIDGET_SLIDER(wSliderBase, $
  707.                         VALUE=0, MINIMUM=-180, MAXIMUM=180, $
  708.                         UVALUE='ZROTATION')
  709.  
  710.                     wSliderZLabel = WIDGET_LABEL(wSliderBase, $
  711.                         VALUE='Z Axis')
  712.  
  713.                 wPopInfoBase = WIDGET_BASE(wLeftBase, /COLUMN, $
  714.                     /FRAME, YPAD=8, XPAD=8, MAP=mapFlag)
  715.  
  716.                     wPopInfoButton = WIDGET_BUTTON(wPopInfoBase, $
  717.                         VALUE='Message', UVALUE='POPINFO')
  718.  
  719.         ;  Create the status label.
  720.         ;
  721.         wStatusBase = WIDGET_BASE(wLeftBase, /COLUMN, /FRAME, $
  722.             YPAD=0, XPAD=0, MAP=mapFlag)
  723.  
  724.             wStatusLabel = WIDGET_LABEL(wStatusBase, /ALIGN_LEFT, $
  725.                 VALUE='Widgets are active.')
  726.  
  727.             ;  Create a base for the left column.
  728.             ;
  729.             wRightBase = WIDGET_BASE(wSubBase, /COLUMN)
  730.  
  731.                 wTopRightBase = WIDGET_BASE(wRightBase, /ROW)
  732.  
  733.                 wColorBase = WIDGET_BASE(wTopRightBase, /COLUMN, $
  734.                     /FRAME, MAP=mapFlag)
  735.  
  736.                     wColorLabel = WIDGET_LABEL(wColorBase, $
  737.                         VALUE='Surface color')
  738.  
  739.                     wColorList = WIDGET_LIST(wColorBase, VALUE=['White', $
  740.                         'Yellow', 'Red', 'Hue'], YSIZE=2, UVALUE='COLORLIST')
  741.  
  742.                 wTextBase = WIDGET_BASE(wTopRightBase, /COLUMN, $
  743.                     /FRAME, YPAD=8, XPAD=8, MAP=mapFlag)
  744.  
  745.                     cwTextField = CW_FIELD(wTextBase, $
  746.                         /RETURN_EVENTS, /COLUMN, /STRING, $
  747.                         TITLE='Status label', VALUE='Widgets are active.', $
  748.                         UVALUE='TITLEFIELD')
  749.  
  750.                 wTableBase = WIDGET_BASE(wRightBase, /COLUMN, $
  751.                     YPAD=0, XPAD=0, MAP=mapFlag)
  752.  
  753.                     sizeX = SIZE(xArray)
  754.                     sizeY = SIZE(yArray)
  755.                     wDataTable = WIDGET_TABLE(wTableBase, $
  756.                         VALUE=data, /EDITABLE, /ALL_EVENTS, $
  757.                         XSIZE=sizeX(1), YSIZE=sizeY(1), $
  758.                         X_SCROLL_SIZE=2, Y_SCROLL_SIZE=2 )
  759.  
  760.  
  761.                 wDrawBase = WIDGET_BASE(wRightBase, /COLUMN, $
  762.                     /FRAME, YPAD=8, XPAD=8, MAP=mapFlag, UVALUE=-1)
  763.  
  764.                     wAreaDraw = WIDGET_DRAW(wDrawBase, $
  765.                         XSIZE=xdim, YSIZE=ydim, /BUTTON_EVENTS, $
  766.                         /EXPOSE_EVENTS, UVALUE='DRAW', $
  767.                         GRAPHICS_LEVEL=2, $
  768.                         NOTIFY_REALIZE='GetDrawID')
  769.  
  770.         ;  Create the status line label.
  771.         ;
  772.         wTipBase = WIDGET_BASE(wCWBase, MAP=0, /ROW)
  773.  
  774.             nWidgets = 2
  775.             wText = LONARR(nWidgets)
  776.             widTips, wTipBase, sText.text, XSIZE=36, $
  777.                 YSIZE=3, NWIDGETS=nWidgets, wText
  778.  
  779.  
  780.     ;  Realize the widget hierarchy
  781.     ;
  782.     WIDGET_CONTROL, wCWBase, /REALIZE
  783.  
  784.     ;  Size the tips widgets. Unmap the tips.
  785.     ;
  786.     sizeTips, wCWBase, wText, wTipBase
  787.     WIDGET_CONTROL, wTipBase, MAP=0
  788.  
  789.     ;  Set the default list and droplist items.
  790.     ;
  791.     WIDGET_CONTROL, wStyleDroplist, SET_DROPLIST_SELECT=1 
  792.     WIDGET_CONTROL, wColorlist, SET_LIST_SELECT=3 
  793.  
  794.     ;  Set the view such that the surface is
  795.     ;  contained within a box defined by
  796.     ;  by radx and rady ( view normal coordinates).
  797.     ;
  798.     sqr3 = SQRT(3)/1.5   ; length of a diagonal in a cube
  799.     radx = SQRT(2.0)       ; viewport in normal coordinates
  800.     rady = SQRT(2.0)
  801.  
  802.     ;  Select the normal corrdinates of the
  803.     ;  orthogonal axes location within the volume.
  804.     ;  example:
  805.     ;  middle :  axesX, axesY, axesZ = -0.5
  806.     ;  lowest data values : axesX, axesY, axesZ = 0.0
  807.     ;  highest data values : axesX, axesY, axesZ = -1.0
  808.     ;               
  809.     axesX = -0.5  
  810.     axesY = -0.5
  811.     axesZ = -0.5
  812.  
  813.     xMargin = (1.0-sqr3)/2.0
  814.     yMargin = (1.0-sqr3)/2.0
  815.     xv = ((xMargin)*radx + axesX)
  816.     yv = ((yMargin)*rady + axesY)
  817.     width = 1.0 - 2.0 * xMargin* radx
  818.     height = 1.0 - 2.0 * yMargin * radY
  819.  
  820.     myview = [xv, yv, width, height]
  821.  
  822.     ;  Create view.
  823.     ;
  824.     oView = OBJ_NEW('idlgrview', PROJECTION=2, EYE=3, $
  825.         ZCLIP=[1.5, -1.5], VIEWPLANE_RECT=myview, COLOR=[0,0,0])
  826.  
  827.     ;  Create model. 
  828.     ;
  829.     oStaticModel = OBJ_NEW('idlgrmodel')
  830.     oMovableModel = OBJ_NEW('idlgrmodel')
  831.     oRotationModel = OBJ_NEW('idlgrmodel')
  832.     oScalingModel = OBJ_NEW('idlgrmodel')
  833.     oTranslationModel = OBJ_NEW('idlgrmodel')
  834.  
  835.     oStaticModel->Add, oMovableModel
  836.     oMovableModel->Add, oRotationModel
  837.     oRotationModel->Add, oScalingModel
  838.     oScalingModel->Add, oTranslationModel
  839.  
  840.     sc = 0.7
  841.     oStaticModel->Scale, sc, sc, sc
  842.  
  843.     ;  Create light.
  844.     ;
  845.     oLight1 = OBJ_NEW('idlgrLight', TYPE=1, INTENSITY=0.8, $
  846.         LOCATION=[2,2,2])
  847.     oLight2 = OBJ_NEW('idlgrLight', TYPE=0, $
  848.         INTENSITY=0.8)
  849.     oTranslationModel->Add, oLight1
  850.     oTranslationModel->Add, oLight2
  851.  
  852.     ;  Compute coordinate conversion to normalize.
  853.     ;
  854.     z = data
  855.     sz = SIZE(z)
  856.     maxx = sz(1) - 1
  857.     maxy = sz(2) - 1
  858.     maxz = MAX(z,min=minz)
  859.     xs = [axesX,1.0/maxx]
  860.     ys = [axesY,1.0/maxy]
  861.     minz2 = minz - 1
  862.     maxz2 = maxz + 1
  863.     zs = [(-minz2/(maxz2-minz2))+axesZ, 1.0/(maxz2-minz2)]
  864.  
  865.     ; For height fields, use the following vertex colors.
  866.     ;
  867.     xDimension = sz(1)   
  868.     yDimension = sz(2)
  869.     vertexColors = BYTARR(3,xDimension*yDimension, /NOZERO)
  870.     shades2 = FLTARR(xDimension*yDimension)
  871.     temp = FLTARR(xDimension, yDimension)
  872.     xtot = xDimension * yDimension
  873.     temp = data
  874.     shades2(0:xtot-1) = temp(0:xDimension-1, 0:yDimension-1)
  875.     maxDataValue = 9          ;  Maximum and mimimum value allowed
  876.     minDataValue = 0          ;  in the data set.
  877.     maxShades = maxDataValue
  878.     minShades = minDataValue
  879.     sat = 1.0
  880.     val = 1.0
  881.     maxAngle = 225.0  ; ( angle is  0 < .. < 360 )
  882.     for j = 0, xtot-1 do begin
  883.         angle =ROUND(  (shades2(j) - minShades) / $
  884.             (maxShades-minShades) * maxAngle )
  885.         Color_convert, angle, sat, val, red, green, blue, /HSV_RGB
  886.         vertexColors(0, j) = red
  887.         vertexColors(1, j) = green
  888.         vertexColors(2, j) = blue
  889.     endfor
  890.  
  891.     ;  Create the surface.
  892.     ;
  893.     oSimpleSurface = OBJ_NEW('IDLgrSurface', data, xarray, yarray, $
  894.         STYLE=2, SHADING=1, $
  895.         COLOR=[60,60,255], BOTTOM=[64,192,128], $
  896.         XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs)
  897.  
  898.     oTranslationModel->Add, oSimpleSurface
  899.  
  900.     ;  Make the surface in color.
  901.     ;
  902.     oSimpleSurface->SetProperty, VERT_COLORS=vertexColors
  903.  
  904.     ;  Rotate the original display.
  905.     ;
  906.     oRotationModel->Rotate, [1,0,0], -45 
  907.     oRotationModel->Rotate, [0,1,0], 45 
  908.  
  909.     ; Place the model in the view.
  910.     ;
  911.     oView->Add, oStaticModel
  912.  
  913.     WIDGET_CONTROL, wDrawBase, GET_UVALUE=temp, /NO_COPY
  914.         oWindowID = temp
  915.     WIDGET_CONTROL, wDrawBase, SET_UVALUE=temp, /NO_COPY
  916.     oWindowID->Draw, oView
  917.  
  918.     ;  Add the trackball object for interactive change
  919.     ;  of the scene orientation
  920.     ;
  921.     oTrack = OBJ_NEW('Trackball', [xdim/2.0, ydim/2.0], xdim/2.0)
  922.  
  923.     oContainer = OBJ_NEW('IDLgrContainer')
  924.     oContainer->Add, oView
  925.     oContainer->Add, oTrack
  926.  
  927.  
  928.     ;  Create the info structure.
  929.     ;
  930.     sInfo = { $
  931.         center: xdim/2., $                      ; Center of unit sphere
  932.         radius: ydim/2, $                       ; Radius of unit sphere
  933.         pt0: FLTARR(3), $                       ; Initial point of rotation
  934.         pt1: FLTARR(3), $                       ; Final point of rotation
  935.         dragq: 'LOW', $                         ; Drag quality(0=low, 1=med,2=high)
  936.         BtnDown: 0, $                           ; mouse button down flag
  937.         OTrack: oTrack, $                       ; Trackball object
  938.         OContainer: oContainer, $               ; Container object
  939.         OView: oView, $                         ; View object
  940.         OStaticModel: oStaticModel, $           ; Models objects
  941.         OMovableModel: oMovableModel, $
  942.         ORotationModel: oRotationModel, $
  943.         OScalingModel: oScalingModel, $
  944.         OTranslationModel: oTranslationModel, $
  945.         OSimpleSurface: oSimpleSurface, $       ; Surface object
  946.         OWindowID: oWindowID, $
  947.         WDataTable: wDataTable, $               ; Widget table ID
  948.         WDrawBase: wDrawBase, $                 ; Widget bases ID
  949.         WStyleBase: wStyleBase, $
  950.         WColorBase: wColorBase, $
  951.         WTextBase: wTextBase, $
  952.         WSliderBase: wSliderBase, $
  953.         WPopInfoBase: wPopInfoBase, $
  954.         WTableBase: wTableBase, $
  955.         WStatusBase: wStatusBase, $
  956.         WTipBase: wTipBase, $
  957.         Parent: parent, $                       ; Parent of cwtable.pro
  958.         WXSlider: wXSlider, $                   ; Widget sliders ID
  959.         WYSlider: wYSlider, $
  960.         WZSlider: wZSlider, $
  961.         WStatusLabel: wStatusLabel, $           ; Widget label ID
  962.         WAreaDraw: wAreaDraw, $                 ; Widget draw ID
  963.         CWTextField: cWTextField, $             ; C-Widget text ID
  964.         Xdimension: xdimension, $               ; X data dimansion
  965.         Ydimension: ydimension, $               ; Y data dimension
  966.         VertexColors: VertexColors, $           ; Vertex colors array
  967.         VertexFlag: 1, $                        ; Vertex olor flag
  968.         MaxDataValue: maxDataValue, $           ; Max. value of data allowed
  969.         MinDataValue: minDataValue $            ; Min. value of data allowed
  970.     }
  971.  
  972.     ;  Put the sInfo as user value of the top level base's first child
  973.     ;
  974.     child =  WIDGET_INFO( wCWBASE, /CHILD)
  975.     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  976.  
  977.     XMANAGER,'cwtable', wCWBase, EVENT_HANDLER='MyTable_Event', $
  978.         /NO_BLOCK
  979.     
  980.     RETURN, wCWBase
  981.  
  982. end
  983.  
  984.  
  985. ; -----------------------------------------------------------------------------
  986. ;
  987. ;  PURPOSE : main event handler
  988. ;
  989. pro widgets_Event, $
  990.     sEvent    ; IN: event structure
  991.  
  992.     ;  Quit the application using the close box.
  993.     ;
  994.     if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
  995.         'WIDGET_KILL_REQUEST') then begin
  996.         WIDGET_CONTROL, sEvent.top, /DESTROY
  997.         RETURN
  998.     endif
  999.  
  1000.     ;  Branch the event accordingly to its name and its user value.
  1001.     ;
  1002.     eventName = WIDGET_INFO(sEvent.id, /NAME)
  1003.     case eventName of
  1004.  
  1005.     'DRAW' : begin
  1006.         WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  1007.  
  1008.         ;  Expose.
  1009.         ;
  1010.         if (sEvent.type eq 4) then begin
  1011.             sState.oWindowID->Draw, sState.oView
  1012.         endif
  1013.  
  1014.         WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  1015.  
  1016.     end
  1017.  
  1018.     'BUTTON' : begin
  1019.  
  1020.     WIDGET_CONTROL, sEvent.id, GET_UVALUE=uvalue
  1021.  
  1022.     case uvalue of
  1023.  
  1024.         'NEXT' : begin
  1025.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  1026.  
  1027.             ;  If the cwtable compound widget  has been destroyed
  1028.             ;  then distroy the main base also and
  1029.             ;  exit this application.
  1030.             ;
  1031.             result = WIDGET_INFO(sState.wCWBase, /VALID_ID)
  1032.             if (result EQ 0) then begin
  1033.                 WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  1034.                 WIDGET_CONTROL, sEvent.top, /DESTROY
  1035.                 RETURN
  1036.             end
  1037.  
  1038.             case sState.index of
  1039.  
  1040.                 ;  Show the base
  1041.                 ;
  1042.                 0 : begin
  1043.                     WIDGET_CONTROL, sState.wUnLabel, $
  1044.                         SET_VALUE='Press NEXT to build a droplist'
  1045.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1046.                         SET_VALUE='Or press QUIT to quit'
  1047.                     WIDGET_CONTROL, sState.wCWBase, MAP=1
  1048.                     sState.oModel->Add, sState.oImageArray(1)
  1049.                     sState.oModel->Remove, sState.oImageArray(0)
  1050.                     sState.oWindowID->Draw, sState.oView
  1051.                 end        ;  of 0
  1052.  
  1053.                 ;  Show the droplist
  1054.                 ;
  1055.                 1 : begin
  1056.                     WIDGET_CONTROL, sState.wUnLabel, $
  1057.                         SET_VALUE='Press NEXT to build a list'
  1058.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1059.                         SET_VALUE='Or press QUIT to quit'
  1060.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1061.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1062.                     WIDGET_CONTROL, sInfo.wStyleBase, MAP=1
  1063.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1064.                     sState.oModel->Add, sState.oImageArray(2)
  1065.                     sState.oModel->Remove, sState.oImageArray(1)
  1066.                     sState.oWindowID->Draw, sState.oView
  1067.                 end        ;  of 1
  1068.  
  1069.                 ;  Show the list for color selection
  1070.                 ;
  1071.                 2 : begin
  1072.                     WIDGET_CONTROL, sState.wUnLabel, $
  1073.                         SET_VALUE='Press NEXT to build a text'
  1074.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1075.                         SET_VALUE='Or press QUIT to quit'
  1076.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1077.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1078.                     WIDGET_CONTROL, sInfo.wColorBase, MAP=1
  1079.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1080.                     sState.oModel->Add, sState.oImageArray(3)
  1081.                     sState.oModel->Remove, sState.oImageArray(2)
  1082.                     sState.oWindowID->Draw, sState.oView
  1083.                 end        ;  of 2
  1084.  
  1085.                 ;  Show the editable text widget
  1086.                 ;
  1087.                 3 : begin
  1088.                     WIDGET_CONTROL, sState.wUnLabel, $
  1089.                         SET_VALUE='Press NEXT to build sliders'
  1090.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1091.                         SET_VALUE='Or press QUIT to quit'
  1092.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1093.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1094.                     WIDGET_CONTROL, sInfo.wTextBase, MAP=1
  1095.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1096.                     sState.oModel->Add, sState.oImageArray(4)
  1097.                     sState.oModel->Remove, sState.oImageArray(3)
  1098.                     sState.oWindowID->Draw, sState.oView
  1099.                 end        ;  of 3
  1100.  
  1101.                 ;  Show three sliders for object rotation
  1102.                 ;
  1103.                 4 : begin
  1104.                     WIDGET_CONTROL, sState.wUnLabel, $
  1105.                         SET_VALUE='Press NEXT to build a message button'
  1106.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1107.                         SET_VALUE='Or press QUIT to quit'
  1108.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1109.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1110.                     WIDGET_CONTROL, sInfo.wSliderBase, MAP=1
  1111.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1112.                     sState.oModel->Add, sState.oImageArray(5)
  1113.                     sState.oModel->Remove, sState.oImageArray(4)
  1114.                     sState.oWindowID->Draw, sState.oView
  1115.                 end        ;  of 4
  1116.  
  1117.                 ;  Show the table widget
  1118.                 ;
  1119.                 5 : begin
  1120.                     WIDGET_CONTROL, sState.wUnLabel, $
  1121.                         SET_VALUE='Press NEXT to build a table'
  1122.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1123.                         SET_VALUE='Or press QUIT to quit'
  1124.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1125.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1126.                     WIDGET_CONTROL, sInfo.wPopInfoBase, MAP=1
  1127.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1128.                     sState.oModel->Add, sState.oImageArray(6)
  1129.                     sState.oModel->Remove, sState.oImageArray(5)
  1130.                     sState.oWindowID->Draw, sState.oView
  1131.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1132.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1133.                     sInfo.oWindowID->Draw, sInfo.oView
  1134.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1135.                 end        ;  of 5
  1136.  
  1137.                 ;  Show the table widget
  1138.                 ;
  1139.                 6 : begin
  1140.                     WIDGET_CONTROL, sState.wUnLabel, $
  1141.                         SET_VALUE='Press NEXT to build a drawing area'
  1142.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1143.                         SET_VALUE='Or press QUIT to quit'
  1144.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1145.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1146.                     WIDGET_CONTROL, sInfo.wTableBase, MAP=1
  1147.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1148.                     sState.oModel->Add, sState.oImageArray(7)
  1149.                     sState.oModel->Remove, sState.oImageArray(6)
  1150.                     sState.oWindowID->Draw, sState.oView
  1151.                 end        ;  of 6
  1152.  
  1153.                 7 : begin
  1154.                     WIDGET_CONTROL, sState.wUnLabel, $
  1155.                         SET_VALUE='Press NEXT to build a status label'
  1156.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1157.                         SET_VALUE='Or press QUIT to quit'
  1158.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1159.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1160.                     WIDGET_CONTROL, sInfo.wDrawBase, MAP=1
  1161.                     WIDGET_CONTROL, sInfo.wDrawBase, GET_UVALUE=temp, /NO_COPY
  1162.                     oDrawWindowID= temp
  1163.                     oDrawWindowID->Draw, sInfo.oView
  1164.                     WIDGET_CONTROL, sInfo.wDrawBase, SET_UVALUE=temp, /NO_COPY
  1165.            
  1166.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1167.                     sState.oModel->Add, sState.oImageArray(8)
  1168.                     sState.oModel->Remove, sState.oImageArray(7)
  1169.                     sState.oWindowID->Draw, sState.oView
  1170.                 end        ;  of 7
  1171.  
  1172.                 8 : begin
  1173.                     WIDGET_CONTROL, sState.wUnLabel, $
  1174.                         SET_VALUE='The aplication is now operational'
  1175.                     WIDGET_CONTROL, sState.wDeuxLabel, $
  1176.                         SET_VALUE='                     '
  1177.                     WIDGET_CONTROL, sState.wTroisLabel, $
  1178.                         SET_VALUE='Or press QUIT to quit'
  1179.                     child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1180.                     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1181.                     WIDGET_CONTROL, sInfo.wStatusBase, MAP=1
  1182.                     WIDGET_CONTROL, sInfo.wTipBase, MAP=1
  1183.                     WIDGET_CONTROL, sState.wNextButton, SENSITIVE=0
  1184.                     WIDGET_CONTROL, sState.wSkipButton, SENSITIVE=0
  1185.                     sState.oWindowID->Draw, sState.oView
  1186.                     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1187.                 end        ;  of 8
  1188.  
  1189.  
  1190.             endcase
  1191.  
  1192.             sState.index = sState.index + 1
  1193.  
  1194.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  1195.  
  1196.         end        ;   of NEXT
  1197.  
  1198.         'SKIP' : begin
  1199.  
  1200.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  1201.  
  1202.             ;  If the cwtable compound widget  has been destroyed
  1203.             ;  then distroy the main base also and
  1204.             ;  exit this application.
  1205.             ;
  1206.             result = WIDGET_INFO(sState.wCWBase, /VALID_ID)
  1207.             if (result EQ 0) then begin
  1208.                 WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  1209.                 WIDGET_CONTROL, sEvent.top, /DESTROY
  1210.                 RETURN
  1211.             end
  1212.  
  1213.             WIDGET_CONTROL, sState.wNextButton, SENSITIVE=0
  1214.             WIDGET_CONTROL, sState.wSkipButton, SENSITIVE=0
  1215.  
  1216.             WIDGET_CONTROL, sState.wUnLabel, $
  1217.                 SET_VALUE='The aplication is now operational'
  1218.             WIDGET_CONTROL, sState.wDeuxLabel, $
  1219.                 SET_VALUE='                     '
  1220.             WIDGET_CONTROL, sState.wTroisLabel, $
  1221.                 SET_VALUE='Or press QUIT to quit'
  1222.  
  1223.             sState.oModel->Remove, sState.oImageArray(sState.index)
  1224.  
  1225.             sState.oModel->Add, sState.oImageArray(8)
  1226.  
  1227.             ;  Sensitize every bases.
  1228.             ;
  1229.             child = WIDGET_INFO(sState.wCWBase, /CHILD)
  1230.             WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1231.  
  1232.             waitSec = 0.3
  1233.             WIDGET_CONTROL, sState.wCWBase, MAP=1
  1234.             wait, waitSec
  1235.             WIDGET_CONTROL, sInfo.wStyleBase, MAP=1
  1236.             wait, waitSec
  1237.             WIDGET_CONTROL, sInfo.wColorBase, MAP=1
  1238.             wait, waitSec
  1239.             WIDGET_CONTROL, sInfo.wTextBase, MAP=1
  1240.             wait, waitSec
  1241.             WIDGET_CONTROL, sInfo.wSliderBase, MAP=1
  1242.             wait, waitSec
  1243.             WIDGET_CONTROL, sInfo.wPopInfoBase, MAP=1
  1244.             wait, waitSec
  1245.             WIDGET_CONTROL, sInfo.wTableBase, MAP=1
  1246.             wait, waitSec
  1247.             WIDGET_CONTROL, sInfo.wDrawBase, MAP=1
  1248.             wait, waitSec
  1249.             WIDGET_CONTROL, sInfo.wStatusBase, MAP=1
  1250.             wait, waitSec
  1251.             WIDGET_CONTROL, sInfo.wTipBase, MAP=1
  1252.  
  1253.             sState.oWindowID->Draw, sState.oView
  1254.  
  1255.             WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1256.  
  1257.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  1258.         end  ;  of SKIP
  1259.  
  1260.         'QUIT' : begin
  1261.             WIDGET_CONTROL, sEvent.top, /DESTROY
  1262.         end        ;   of QUIT
  1263.  
  1264.     endcase
  1265.     end
  1266.  
  1267.     endcase
  1268.  
  1269. end
  1270.  
  1271. ;----------------------------------------------------------------------------
  1272. ;
  1273. ;  Purpose:  Destroy the top objects and restore the previous
  1274. ;            color table
  1275. ;
  1276. pro Widgets_Cleanup, $
  1277.     wTopBase        ;  IN: top level base identifier
  1278.  
  1279.     WIDGET_CONTROL, wTopBase, GET_UVALUE=sInfo, /NO_COPY
  1280.  
  1281.     ;  Destroy the top objects
  1282.     ;
  1283.     OBJ_DESTROY, sInfo.oCWView
  1284.     OBJ_DESTROY, sInfo.oView
  1285.     OBJ_DESTROY, sInfo.oTrack
  1286.     OBJ_DESTROY, sInfo.oContainer
  1287.     OBJ_DESTROY, sInfo.oImage
  1288.     for i = 0, sInfo.nImage-1 do begin
  1289.         OBJ_DESTROY, sInfo.oImageArray(i)
  1290.     endfor
  1291.     
  1292.     ;  Restore the color table
  1293.     ;
  1294.     TVLCT, sInfo.colorTable
  1295.  
  1296.     if widget_info(sInfo.groupBase, /valid) then $
  1297.         widget_control, sInfo.groupBase, /map
  1298.  
  1299. end   ;  of widgets_Cleanup
  1300.  
  1301. ; -----------------------------------------------------------------------------
  1302. ;
  1303. ;  Purpose:  Main driver of the compound widget cwAllwid.pro.  
  1304. ;
  1305.  
  1306. pro d_widgets, $
  1307.     GROUP=group, $     ; IN: (opt) group identifier
  1308.     APPTLB = appTLB    ; OUT: (opt) TLB of this application
  1309.  
  1310.     ; Check the validity of the group identifier
  1311.     ;
  1312.     ngroup = N_ELEMENTS(group)
  1313.     if (ngroup NE 0) then begin
  1314.         check = widget_INFO(group, /valid)
  1315.         if (check NE 1) then begin
  1316.             print,'Error, the group identifier is not valid'
  1317.             print, 'Return to the main application'
  1318.             RETURN
  1319.         endif
  1320.         groupBase = group
  1321.     endif else groupBase = 0L
  1322.  
  1323.  
  1324.     ;  Get the current color vectors to restore
  1325.     ;  when this application is exited.
  1326.     TVLCT, savedR, savedG, savedB, /GET
  1327.  
  1328.     ; Build color table from color vectors
  1329.     ;
  1330.     colorTable = [[savedR],[savedG],[savedB]]
  1331.  
  1332.     ;  Set up parameters
  1333.     ;
  1334.     mapFlag = 0
  1335.     xOffset = 200
  1336.     yOffset = 200
  1337.    
  1338.     ;  Restore the image file
  1339.     ; 
  1340.     RESTORE, filepath('wwimage.sav', $
  1341.         SUBDIR=['examples','demo','demodata'])
  1342.  
  1343.     ;  Create the top level base
  1344.     ;
  1345.     if( N_ELEMENTS(group) EQ 0) then begin
  1346.         wtopBase = WIDGET_BASE(TITLE='All widgets', $
  1347.             /TLB_KILL_REQUEST_EVENTS, $
  1348.             TLB_FRAME_ATTR=1, /COLUMN, XOFFSET=50, YOFFSET=50)
  1349.     endif else begin
  1350.         wtopBase = WIDGET_BASE(TITLE='All widgets', $
  1351.             /TLB_KILL_REQUEST_EVENTS, $
  1352.             GROUP_LEADER=group, $
  1353.             TLB_FRAME_ATTR=1, /COLUMN, XOFFSET=50, YOFFSET=50)
  1354.     endelse
  1355.  
  1356.         wZeroLabel = WIDGET_LABEL(wTopBase, /ALIGN_LEFT, $
  1357.             VALUE=' ' )
  1358.  
  1359.         wUnLabel = WIDGET_LABEL(wTopBase, /ALIGN_LEFT, $
  1360.             VALUE='Press NEXT to build a base and the menu bar,     ')
  1361.  
  1362.         wDeuxLabel = WIDGET_LABEL(wTopBase, /ALIGN_LEFT, $
  1363.             VALUE='Press SKIP to skip all the steps,                ')
  1364.  
  1365.         wTroisLabel = WIDGET_LABEL(wTopBase, /ALIGN_LEFT,$
  1366.             VALUE='Or press QUIT to exit                             ')
  1367.  
  1368.         wQuatreLabel = WIDGET_LABEL(wTopBase, /ALIGN_LEFT,$
  1369.             VALUE='                                     ')
  1370.  
  1371.         wButtonBase = WIDGET_BASE(wTopBase, /ROW)
  1372.  
  1373.             wSkipButton = WIDGET_BUTTON(wButtonBase, /ALIGN_RIGHT, $
  1374.                 VALUE='<<SKIP>>', UVALUE='SKIP')
  1375.  
  1376.             wNextButton = WIDGET_BUTTON(wButtonBase, /ALIGN_RIGHT, $
  1377.                 VALUE='<<NEXT>>', UVALUE='NEXT')
  1378.  
  1379.             wQuitButton = WIDGET_BUTTON(wButtonBase, /ALIGN_RIGHT, $
  1380.                 VALUE='QUIT', UVALUE='QUIT')
  1381.  
  1382.             wImageDraw = WIDGET_Draw(wButtonBase,  $
  1383.                 XSIZE=maxXImage, YSIZE=maxYImage, RETAIN=0, $
  1384.                 GRAPHICS_LEVEL=2, $
  1385.                 /EXPOSE_EVENTS, UVALUE='IMAGE')
  1386.  
  1387.         wCWBase = cwtable(wTopBase, MAPFLAG=mapFlag, $
  1388.             YOFFSET=yOffset, XOFFSET=xOffset)
  1389.  
  1390.     WIDGET_CONTROL, wTopBase, /REALIZE
  1391.  
  1392.     ; Returns the top level base to the APPTLB keyword.
  1393.     ;
  1394.     appTLB = wtopBase
  1395.  
  1396.     oView = OBJ_NEW('idlgrview', COLOR=[255, 255, 255], $
  1397.         PROJECTION=1, VIEW=[0, 0, maxXimage, maxYimage] )
  1398.  
  1399.     oModel = OBJ_NEW('IDLgrModel')
  1400.     oView->Add, oModel
  1401.  
  1402.     nImage = 9     ;  number of images
  1403.  
  1404.     oImageArray=OBJARR(nImage)
  1405.     oImageArray(0) = OBJ_NEW('idlgrimage', image0)
  1406.     oImageArray(1) = OBJ_NEW('idlgrimage', image1)
  1407.     oImageArray(2) = OBJ_NEW('idlgrimage', image2)
  1408.     oImageArray(3) = OBJ_NEW('idlgrimage', image3)
  1409.     oImageArray(4) = OBJ_NEW('idlgrimage', image4)
  1410.     oImageArray(5) = OBJ_NEW('idlgrimage', image5)
  1411.     oImageArray(6) = OBJ_NEW('idlgrimage', image6)
  1412.     oImageArray(7) = OBJ_NEW('idlgrimage', image7)
  1413.     oImageArray(8) = OBJ_NEW('idlgrimage', image8)
  1414.  
  1415.     oImage = oImageArray(0)
  1416.     oModel->Add, oImage
  1417.  
  1418.     WIDGET_CONTROL, wImageDraw, GET_VALUE=oWindowID
  1419.     oWindowID->Draw, oView
  1420.  
  1421.     child =  WIDGET_INFO( wCWBASE, /CHILD)
  1422.     WIDGET_CONTROL, child, GET_UVALUE=sInfo, /NO_COPY
  1423.     OCWView = sInfo.oView
  1424.     OTrack = sInfo.oTrack
  1425.     OContainer = sInfo.oContainer
  1426.     WIDGET_CONTROL, child, SET_UVALUE=sInfo, /NO_COPY
  1427.  
  1428.  
  1429.     ;  Create the state structure
  1430.     ;
  1431.     sState = { $
  1432.         ColorTable: colorTable, $     ; Color table to restore
  1433.         WNextButton: wNextButton, $   ; Next button ID
  1434.         WSkipButton: wSkipButton, $   ; Skip button ID
  1435.         WQuitButton: wQuitButton, $   ; Quit button ID
  1436.         OWindowID: oWindowID, $       ; Window object
  1437.         OView: oView, $               ; View object
  1438.         WUnLabel: wUnLabel, $         ; Widget labels IDs (un=one)
  1439.         WDeuxLabel: wDeuxLabel, $     ;                   (deux=two)
  1440.         WTroisLabel: wTroisLabel, $   ;                   (trois=three)
  1441.         WQuatreLabel: wQuatreLabel, $ ;                   (quatre=four)
  1442.         Index: 0, $                   ; Step index (0=start , 8=last)
  1443.         OCWView: oCWView, $           ; View object from compound widget
  1444.         OImage: oImage, $             ; Image object
  1445.         OImageArray: oImageArray, $   ; Image object array
  1446.         OModel: oModel, $             ; Top model
  1447.         OTrack: oTrack, $     ; Trackball object from cwtable
  1448.         OContainer: oContainer, $     ; Container object from cwtable
  1449.         NImage: nImage, $             ; Number of images
  1450.         WCWBase: WCWBase, $           ; Top level base of the compound widget
  1451.         groupBase: groupBase $        ; Base of Group Leader
  1452.     }
  1453.  
  1454.     WIDGET_CONTROL, wTopBase, SET_UVALUE=sState, /NO_COPY
  1455.  
  1456.     XMANAGER, 'widgets', wTopBase, /NO_BLOCK, $
  1457.         CLEANUP='widgets_Cleanup'
  1458.  
  1459. end     ; of widgets
  1460.